package com.wn.icloud.service;

import com.wn.icloud.domain.BaseEntityDomain;
import org.springframework.data.domain.Example;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.domain.Sort;
import org.springframework.data.jpa.domain.Specification;
import org.springframework.lang.Nullable;

import java.io.Serializable;
import java.util.List;
import java.util.Optional;

/**
 * @author liguangcai
 * @date 2018/11/30 16:06
 */
public interface BaseService<T extends BaseEntityDomain, ID extends Serializable> {

    List<T> findAll();

    List<T> findAll(Sort sort);

    List<T> findAllById(Iterable<ID> ids);

    <S extends T> List<S> saveAll(Iterable<S> entities);

    void flush();

    <S extends T> S saveAndFlush(S entity);

    void deleteInBatch(Iterable<T> entities);

    void deleteAllInBatch();

    T getOne(ID id);

    <S extends T> List<S> findAll(Example<S> example, Sort sort);

    Page<T> findAll(Pageable pageable);

    <S extends T> Optional<S> findOne(S entity);



    <S extends T> List<S> findAll(S entity);

    <S extends T> Page<S> findAll(S entity, Pageable pageable);

    <S extends T> Page<S> findAll(Example<S> example, Pageable pageable);

    <S extends T> long count(Example<S> example);

    <S extends T> boolean exists(S enitiy);


    <S extends T> S save(S entity);

    Optional<T> findById(ID id);

    boolean existsById(ID id);


    long count();

    void deleteById(ID id);


    void delete(T entity);

    void deleteAll(Iterable<? extends T> entities);

    void deleteAll();

    Optional<T> findOne(@Nullable Specification<T> spec);

    List<T> findAll(@Nullable Specification<T> spec);

    Page<T> findAll(@Nullable Specification<T> spec, Pageable pageable);


    List<T> findAll(@Nullable Specification<T> spec, Sort sort);

    long count(@Nullable Specification<T> spec);


}
